import Vue from 'vue'
import VueRouter from 'vue-router'
import recommend from '../views/recommend.vue'

Vue.use(VueRouter)

const routes = [{
        path: '/',
        redirect: "/recommend"
    },
    {
        path: "/userInfo",
        name: "userInfo",
        component: () =>
            import ("../views/userinfo.vue"),
        beforeEnter: (to, from, next) => {
            let login = window.localStorage.getItem("token");
            // 判断没有值
            if (!login) {
                next("/login");
                return
            } else {
                next();
            }
        }
    },
    {
        path: '/login',
        name: 'login',
        component: () =>
            import ("../components/base/login.vue")

    },
    {
        path: '/recommend',
        name: 'recommend',
        component: recommend
    },
    {
        path: '/singer',
        name: 'singer',
        component: () =>
            import ('../views/singer.vue')
    },
    {
        path: '/rank',
        name: 'rank',
        component: () =>
            import ('../views/rank.vue')
    },
    {
        path: '/search',
        name: 'search',
        component: () =>
            import ('../views/search.vue')
    },
    {
        path: '/recommendcon',
        name: 'recommendcon',
        component: () =>
            import ('../views/recommendcon.vue')
    },
    {
        path: '/personalized',
        name: 'personalized',
        component: () =>
            import ('../views/personalized.vue')
    },
    {
        path: "/rank/ranklist",
        name: "ranklist",
        component: () =>
            import ("../components/rank/ranklist.vue")
    },
    {
        path: '/singer/songs',
        name: 'singer',
        component: () =>
            import ('../components/singer/songs.vue')
    },
    {
        path: '/mvsublist',
        name: 'mvsublist',
        component: () =>
            import ('../components/base/mvsublist.vue')
    },
    {
        path: '/mvscon',
        name: 'mvscon',
        component: () =>
            import ('../views/mvscon.vue')
    },
    {
        path: '/follow',
        name: 'follow',
        component: () =>
            import ('../views/follow.vue')
    },

    // {
    //   path: '/',
    //   name: 'Home',
    //   component: Home
    // },
    // {
    //   path: '/about',
    //   name: 'About',
    //   // route level code-splitting
    //   // this generates a separate chunk (about.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
    // }
]

const router = new VueRouter({
    routes
})

export default router